function [nmodel]=i_mld(dat,model)

% -----------------------------------------------------------
% -- Interpolating modelled fields on observation's position
% -- in the mixed layer climatology case
% -----------------------------------------------------------
% G. Charria (10/2008)


% ---- Create the Structure ...
nmodel = struct('dummy',1);
    

% ---- Control that the model is covering the same period as the data

% ---- Interpolation    
%d1(1:size(model.data,1),1:size(model.data,2),1:size(dat.data,3))=NaN;       
d2(1:size(dat.data,1),1:size(dat.data,2),1:size(dat.data,3))=NaN;
h=waitbar(0,'Horizontal and temporal interpolation ...');

% ---- I. Interpolation over the cruise data (time) ----

d1=monthyl_nemo_mean(model.data,model.time);

%figure
%V=datevec(model.time);
%plot(V(:,2),squeeze(model.data(1,150,150,:)),'.')
%hold on
%plot(squeeze(d1(1,150,150,:)),'r+')
%V=[];
%clear V

% ---- II. Interpolation over the cruise track (lon,lat) ----

for it=1:size(dat.data,3)
    waitbar(  it/size(dat.data,3),h) 
    d2(:,:,it)=griddata(model.lon,model.lat,squeeze(d1(:,:,it)),dat.londata',dat.latdata)';
    % ---
    %figure
    %subplot(1,2,1)
    %pcolor(model.lon,model.lat,squeeze(model.data(iz,:,:,it))); shading flat; colorbar;
    %subplot(1,2,2)
    %pcolor(dat.londata,dat.latdata,squeeze(d2(iz,:,:,it))')
    %shading flat
    %pause            
end     

close(h)        




nmodel.lon=dat.londata;
nmodel.lat=dat.latdata;
nmodel.data=d2;
nmodel.time=dat.timedata;



% ---- Clean the Structure ...
nmodel=rmfield(nmodel,'dummy');    
